box gadget: allow reversing alignments
authorMatthias Clasen <mclasen@redhat.com>
Fri, 29 Apr 2016 01:27:02 +0000 (21:27 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 29 Apr 2016 01:59:34 +0000 (21:59 -0400)
In RTL, we want to interpret GTK_ALIGN_START and _END
in the opposite way. Since we don't give gadgets a text
direction, just allow setting an align_reverse flag
to the box gadget.

gtk/gtkboxgadget.c
gtk/gtkboxgadgetprivate.h

index 6533b6e77a597736ba43bb7a39f8a2a6c293b4a2..e8198d7d97a1315223450020158c77a7c6079c81 100644 (file)
@@ -38,9 +38,10 @@ struct _GtkBoxGadgetPrivate {
   GtkOrientation orientation;
   GArray *children;
 
-  guint draw_focus : 1;
-  guint draw_reverse : 1;
+  guint draw_focus       : 1;
+  guint draw_reverse     : 1;
   guint allocate_reverse : 1;
+  guint align_reverse    : 1;
 };
 
 typedef gboolean (* ComputeExpandFunc) (GObject *object, GtkOrientation orientation);
@@ -84,6 +85,21 @@ gtk_box_gadget_child_get_align (GtkBoxGadget      *gadget,
   return align;
 }
 
+static GtkAlign
+effective_align (GtkAlign align,
+                 gboolean reverse)
+{
+  switch (align)
+    {
+    case GTK_ALIGN_START:
+      return reverse ? GTK_ALIGN_END : GTK_ALIGN_START;
+    case GTK_ALIGN_END:
+      return reverse ? GTK_ALIGN_START : GTK_ALIGN_END;
+    default:
+      return align;
+    }
+}
+
 static void
 gtk_box_gadget_measure_child (GObject        *child,
                               GtkOrientation  orientation,
@@ -304,6 +320,7 @@ gtk_box_gadget_allocate_child (GObject        *child,
                                              allocation->width,
                                              &minimum, &natural,
                                              &minimum_baseline, &natural_baseline);
+
           switch (child_align)
             {
             case GTK_ALIGN_FILL:
@@ -407,7 +424,7 @@ gtk_box_gadget_allocate (GtkCssGadget        *gadget,
           child_align = gtk_box_gadget_child_get_align (GTK_BOX_GADGET (gadget), child);
           gtk_box_gadget_allocate_child (child->object,
                                          priv->orientation,
-                                         child_align,
+                                         effective_align (child_align, priv->align_reverse),
                                          &child_allocation,
                                          baseline,
                                          &child_clip);
@@ -441,7 +458,7 @@ gtk_box_gadget_allocate (GtkCssGadget        *gadget,
           child_align = gtk_box_gadget_child_get_align (GTK_BOX_GADGET (gadget), child);
           gtk_box_gadget_allocate_child (child->object,
                                          priv->orientation,
-                                         child_align,
+                                         effective_align (child_align, priv->align_reverse),
                                          &child_allocation,
                                          -1,
                                          &child_clip);
@@ -595,6 +612,15 @@ gtk_box_gadget_set_allocate_reverse (GtkBoxGadget *gadget,
   priv->allocate_reverse = allocate_reverse;
 }
 
+void
+gtk_box_gadget_set_align_reverse (GtkBoxGadget *gadget,
+                                  gboolean      align_reverse)
+{
+  GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget);
+
+  priv->align_reverse = align_reverse;
+}
+
 static GtkCssNode *
 get_css_node (GObject *child)
 {
index 008fd1671b68883f73d679a99aa3302a111e8a81..ce1a667a29fbe6bc850d6635fc96f00d99a46503 100644 (file)
@@ -63,6 +63,8 @@ void                    gtk_box_gadget_set_draw_reverse         (GtkBoxGadget
 void                    gtk_box_gadget_set_allocate_reverse     (GtkBoxGadget           *gadget,
                                                                  gboolean                allocate_reverse);
 
+void                    gtk_box_gadget_set_align_reverse        (GtkBoxGadget           *gadget,
+                                                                 gboolean                align_reverse);
 void                    gtk_box_gadget_insert_widget            (GtkBoxGadget           *gadget,
                                                                  int                     pos,
                                                                  GtkWidget              *widget);